package com.iflytek.cosmo.ocr.model.domain;


import com.iflytek.cosmo.ocr.common.constant.CommonConstant;
import io.swagger.annotations.ApiModel;

@ApiModel(value = "the response common message type")
public class MessageOutput<T> {
	/**
	 * 状态
	 */
	private State state;
	/**
	 * 数据对象
	 */
	private T body;
	
	public MessageOutput(State state) {
		super();
		this.state = state;
	}

	public MessageOutput(State state, T body) {
		super();
		this.state = state;
		this.body = body;
	}

    public static <T> MessageOutput<T> success(T body) {
        return new MessageOutput<>(new State(CommonConstant.SUCCESS_CODE), body);
    }

    public static <T> MessageOutput<T> failed(Class<T> resultClass) {
        return new MessageOutput<>(new State(CommonConstant.FAIL_CODE));
    }

    public static <T> MessageOutput<T> failed(Class<T> resultClass, String failReason) {
        return new MessageOutput<>(new State(CommonConstant.FAIL_CODE, failReason));
    }

    public static <T> MessageOutput<T> failed(Class<T> resultClass, int code, String failReason) {
        return new MessageOutput<>(new State(code, failReason));
    }

    public State getState() {
		return state;
	}

	public void setState(State state) {
		this.state = state;
	}

	public T getBody() {
		return body;
	}

	public void setBody(T body) {
		this.body = body;
	}
}
